package com.asiainfo.sqlextractor.functions;

import com.alibaba.fastjson.JSON;
import com.asiainfo.sqlextractor.util.JavaTypeResolve;

import java.util.LinkedHashMap;
import java.util.Map;

public class Functions {

    public static Object callFunc(String apiName, Object... args) {
        Map<String, Object> params = extractArguments(args);
        System.out.println("调用函数" + apiName + "  " + JSON.toJSONString(params));
        return "callFunc";
    }

    public static Object callApi(String apiName, Object... args) {
        Map<String, Object> params = extractArguments(args);
        System.out.println("调用函数" + apiName + "  " + JSON.toJSONString(params));
        return "callApi";
    }

    public static Object callScript(String apiName, Object... args) {
        Map<String, Object> params = extractArguments(args);
        System.out.println("调用函数" + apiName + "  " + JSON.toJSONString(params));
        return "callScript";
    }

    private static Map<String, Object> extractArguments(Object[] args) {
        Map<String, Object> params = new LinkedHashMap<>(args.length / 2);
        for (int i = 0; i < args.length - 1; i += 2) {
            params.put((String) args[i], args[i + 1]);
        }
        return params;
    }

}
